package com.bnq.control.desktop.utils;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;

import androidx.core.content.ContextCompat;

import com.bnq.control.common.constant.StorageConstant;
import com.bnq.control.common.factory.StorageFactoryManager;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by qianwei on 2019/8/7.
 */

public class SurfaceRecordUtils {

    private static final String FILE_SUFFIX = ".mp4";           // 视频录制格式不能更改

    public static String getFilePath(Context context) {
        return StorageFactoryManager.getInstance().getStoragePath(context, StorageConstant.DOWNLOAD_PATH);
    }

    public static String getFileName() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd_HH_mm_ss", Locale.CHINA);
        return simpleDateFormat.format(new Date()) + getFileSuffix();
    }

    private static String getFileSuffix() {
        return FILE_SUFFIX;
    }

    public static boolean hasPermission(Context context, String... permissions) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return true;
        boolean isGrant;
        for (String permission : permissions) {
            isGrant = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
            if (!isGrant) return false;
        }
        return true;
    }
}
